package org.noteit.gui;

import java.util.Calendar;
import org.noteit.db.CodeManager;
import org.noteit.helper.note;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JOptionPane;
/*
 * MainFrame.java
 *
 * Created on August 9, 2007, 12:24 PM
 */
import org.noteit.db.h2debugger;
import org.noteit.helper.timetable;

/**
 *
 * @author  Owner
 */
public class MainFrame extends javax.swing.JFrame {

    CodeManager cm = new CodeManager();
    note n = new note();
    TrayIcon trayIcon;
    boolean adding = false;
    boolean editing = false;
    boolean binded = false;
    static MainFrame frame;
    int modeFlag = 0; //0 - Note mode, 1 - Time Table mode
    String[] daysArray = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
    boolean initH2Debug = false;

    /** Creates new form MainFrame */
    public MainFrame() {
        initComponents();
        initTrayIcon();
        setSize(350, 200);
        initH2Debugger();
        noteMode();
//        ImageIcon i = (new ImageIcon(getClass().getResource("images/NoteIt-icon.gif")));
//        setIconImage(i.getImage());
    }

    private void initNoteComboBox() {
        namebox.removeAllItems();
        ArrayList aList = cm.getAllSubjectNames();
        for (int i = 0; i < aList.size(); i++) {
            namebox.addItem((String) aList.get(i));
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        deleteBtn = new javax.swing.JButton();
        basePane = new javax.swing.JPanel();
        controlPane = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        controlPane2 = new javax.swing.JPanel();
        namebox = new javax.swing.JComboBox();
        jButton6 = new javax.swing.JButton();
        controlPane3 = new javax.swing.JPanel();
        cancelBTN = new javax.swing.JButton();
        saveBTN = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jPanel2 = new javax.swing.JPanel();
        jToolBar1 = new javax.swing.JToolBar();
        newBTN = new javax.swing.JButton();
        editBTN = new javax.swing.JButton();
        clearBTN = new javax.swing.JButton();
        modeBtn = new javax.swing.JButton();
        exitBtn = new javax.swing.JButton();
        jToolBar3 = new javax.swing.JToolBar();
        backBTN = new javax.swing.JButton();
        jToolBar4 = new javax.swing.JToolBar();
        nextBTN = new javax.swing.JButton();

        deleteBtn.setText("Delete");
        deleteBtn.setToolTipText("Delete this note");
        deleteBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteBtnActionPerformed(evt);
            }
        });

        setTitle("NoteIt !");
        setForeground(java.awt.Color.white);
        setIconImage(getIconImage());

        basePane.setLayout(new java.awt.BorderLayout());

        controlPane.setLayout(new java.awt.BorderLayout());

        jPanel1.setLayout(new java.awt.BorderLayout());

        controlPane2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        controlPane2.add(namebox);

        jButton6.setText("Go");
        jButton6.setToolTipText("");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });
        controlPane2.add(jButton6);

        jPanel1.add(controlPane2, java.awt.BorderLayout.WEST);

        cancelBTN.setText("Cancel");
        cancelBTN.setToolTipText("Cancel operation");
        cancelBTN.setEnabled(false);
        cancelBTN.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelBTNActionPerformed(evt);
            }
        });
        controlPane3.add(cancelBTN);

        saveBTN.setText("Save");
        saveBTN.setToolTipText("Save this note");
        saveBTN.setAutoscrolls(true);
        saveBTN.setEnabled(false);
        saveBTN.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        saveBTN.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveBTNActionPerformed(evt);
            }
        });
        controlPane3.add(saveBTN);

        jPanel1.add(controlPane3, java.awt.BorderLayout.EAST);

        controlPane.add(jPanel1, java.awt.BorderLayout.NORTH);

        jScrollPane1.setBorder(javax.swing.BorderFactory.createEtchedBorder(null, new java.awt.Color(0, 0, 0)));

        jTextArea1.setBackground(javax.swing.UIManager.getDefaults().getColor("Panel.background"));
        jTextArea1.setColumns(20);
        jTextArea1.setLineWrap(true);
        jTextArea1.setRows(5);
        jTextArea1.setToolTipText("Text");
        jTextArea1.setWrapStyleWord(true);
        jTextArea1.setDragEnabled(true);
        jScrollPane1.setViewportView(jTextArea1);

        controlPane.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        basePane.add(controlPane, java.awt.BorderLayout.CENTER);

        getContentPane().add(basePane, java.awt.BorderLayout.CENTER);

        jPanel2.setLayout(new java.awt.BorderLayout());

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);

        newBTN.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/addnote-icon.gif"))); // NOI18N
        newBTN.setToolTipText("New Note");
        newBTN.setPreferredSize(new java.awt.Dimension(27, 34));
        newBTN.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newBTNActionPerformed(evt);
            }
        });
        jToolBar1.add(newBTN);

        editBTN.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/editnote-icon.gif"))); // NOI18N
        editBTN.setToolTipText("Edit Note");
        editBTN.setPreferredSize(new java.awt.Dimension(27, 34));
        editBTN.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editBTNActionPerformed(evt);
            }
        });
        jToolBar1.add(editBTN);

        clearBTN.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/clearnote-icon.gif"))); // NOI18N
        clearBTN.setToolTipText("Clear Text");
        clearBTN.setPreferredSize(new java.awt.Dimension(27, 34));
        clearBTN.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearBTNActionPerformed(evt);
            }
        });
        jToolBar1.add(clearBTN);

        modeBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/NoteIt !-icon1.gif"))); // NOI18N
        modeBtn.setToolTipText("Exit NoteIt !");
        modeBtn.setFocusable(false);
        modeBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        modeBtn.setPreferredSize(new java.awt.Dimension(27, 34));
        modeBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        modeBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                modeBtnActionPerformed(evt);
            }
        });
        jToolBar1.add(modeBtn);

        exitBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/NoteIt !-icon1.gif"))); // NOI18N
        exitBtn.setToolTipText("Exit NoteIt !");
        exitBtn.setFocusable(false);
        exitBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        exitBtn.setPreferredSize(new java.awt.Dimension(27, 34));
        exitBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        exitBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitBtnActionPerformed(evt);
            }
        });
        jToolBar1.add(exitBtn);

        jPanel2.add(jToolBar1, java.awt.BorderLayout.CENTER);

        jToolBar3.setFloatable(false);
        jToolBar3.setRollover(true);

        backBTN.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/left.gif"))); // NOI18N
        backBTN.setToolTipText("Back");
        backBTN.setFocusable(false);
        backBTN.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        backBTN.setPreferredSize(new java.awt.Dimension(34, 34));
        backBTN.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        backBTN.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backBTNActionPerformed(evt);
            }
        });
        jToolBar3.add(backBTN);

        jPanel2.add(jToolBar3, java.awt.BorderLayout.WEST);

        jToolBar4.setFloatable(false);
        jToolBar4.setRollover(true);

        nextBTN.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/right.gif"))); // NOI18N
        nextBTN.setToolTipText("Next");
        nextBTN.setFocusable(false);
        nextBTN.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        nextBTN.setPreferredSize(new java.awt.Dimension(34, 34));
        nextBTN.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        nextBTN.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nextBTNActionPerformed(evt);
            }
        });
        jToolBar4.add(nextBTN);

        jPanel2.add(jToolBar4, java.awt.BorderLayout.EAST);

        getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public void restore() {
        this.setVisible(true);
    }

    public void initH2Debugger() {
        if (initH2Debug == true) {
            new h2debugger(cm.getConnection()).start();
        }
    }

    public void noteMode() {
        initNote();
        modeFlag = 0;
        modeBtn.setToolTipText("Note mode");
    }

    public void timetableMode() {
        initTimeTable();
        modeFlag = 1;
        modeBtn.setToolTipText("Time Table mode");
    }

    public void initNote() {
        initNoteComboBox();
        n = cm.getFirstNote();
        namebox.setSelectedItem(Integer.toString(n.getNoteid()));
        jTextArea1.setText(n.getContent());
    }

    public void initTimeTable() {
        initTimeTableComboBox();
        String weekday = this.getWeekday();
        timetable tt = cm.getTimeTableByDay(weekday);
        namebox.setSelectedItem(weekday);
        jTextArea1.setText(tt.getContent());
    }

    public void initTimeTableComboBox() {
        namebox.removeAllItems();
        for (int i = 0; i < daysArray.length; i++) {
            namebox.addItem((String) daysArray[i]);
        }
    }

    public void nextNote() {
        String noteSelected = (String) namebox.getSelectedItem();
        if (noteSelected.equals("")) {
            JOptionPane.showMessageDialog(this, "Enter a valid id for next.", "Empty Field", JOptionPane.WARNING_MESSAGE);
            return;
        } else {
            n = cm.nextNote(noteSelected);
            if (n.getNoteid() != 0) {
                namebox.setSelectedItem(n.getSubject());
                jTextArea1.setText(n.getContent());
            }
        }
    }

    public void previousNote() {
        if (namebox.getSelectedItem().toString().equals("")) {
            JOptionPane.showMessageDialog(this, "Enter a valid id for previous.", "Empty Field", JOptionPane.WARNING_MESSAGE);
            return;
        } else {
            n = cm.previousNote(namebox.getSelectedItem().toString());
            if (n.getNoteid() != 0) {
                namebox.setSelectedItem(n.getSubject());
                jTextArea1.setText(n.getContent());
            }
        }
    }

    public boolean addNote() {
        boolean ok = cm.addNote((String) jTextArea1.getText());
        if (ok == true) {
            saveBTN.setEnabled(false);
            cancelBTN.setEnabled(false);
            newBTN.setEnabled(true);
            editBTN.setEnabled(true);
            namebox.setEnabled(true);
            jButton6.setEnabled(true);
            jTextArea1.setText("");
            JOptionPane.showMessageDialog(this, "Note has been successfully saved.", "Save Successful", JOptionPane.INFORMATION_MESSAGE);
            note selectedNote = cm.gotoSubject((String) namebox.getSelectedItem());
            jTextArea1.setText(selectedNote.getContent());
        } else {
            JOptionPane.showMessageDialog(this, "There is an error saving your note. Please check SQL log for more details", "Error Saving Note", JOptionPane.ERROR_MESSAGE);
        }
        return ok;
    }

    public boolean editNote() {
        note note = new note();
        note.setContent(jTextArea1.getText());
        note.setSubject((String) namebox.getSelectedItem());
        boolean ok = cm.update(note);
        if (ok == true) {
            saveBTN.setEnabled(false);
            cancelBTN.setEnabled(false);
            newBTN.setEnabled(true);
            editBTN.setEnabled(true);
            namebox.setEnabled(true);
            jButton6.setEnabled(true);
            jTextArea1.setText("");
            JOptionPane.showMessageDialog(this, "Note has been successfully edited.", "Edit Successful", JOptionPane.INFORMATION_MESSAGE);
            note = cm.gotoSubject((String) namebox.getSelectedItem());
            //noteidTF.setText(Integer.toString(n.getNoteid())); ?
            jTextArea1.setText(note.getContent());
        } else {
            JOptionPane.showMessageDialog(this, "There is an error editing your note. Please check SQL log for more details", "Error Editing Note", JOptionPane.ERROR_MESSAGE);
        }
        return ok;
    }

    public void nextDayTimeTable() {
        String currentDay = (String) namebox.getSelectedItem();
        String nextDay = this.nextDay(currentDay);
        if (nextDay == null) {
            return;
        } else {
            timetable tt = cm.getTimeTableByDay(nextDay);
            namebox.setSelectedItem(tt.getDays());
            jTextArea1.setText(tt.getContent());
        }
    }

    public void previousDayTimeTable() {
        String currentDay = (String) namebox.getSelectedItem();
        String previousDay = this.previousDay(currentDay);
        if (previousDay == null) {
            return;
        } else {
            timetable tt = cm.getTimeTableByDay(previousDay);
            namebox.setSelectedItem(tt.getDays());
            jTextArea1.setText(tt.getContent());
        }
    }

    public boolean saveTimeTable() {
        timetable timetable = new timetable((String) jTextArea1.getText(), (String) namebox.getSelectedItem());
        boolean ok = cm.setTimeTable(timetable);
        if (ok == true) {
            saveBTN.setEnabled(false);
            cancelBTN.setEnabled(false);
            newBTN.setEnabled(true);
            editBTN.setEnabled(true);
            namebox.setEnabled(true);
            jButton6.setEnabled(true);
            jTextArea1.setText("");
            JOptionPane.showMessageDialog(this, "Timetable for " + timetable.getDays() + " has been successfully saved.", "Save Successful", JOptionPane.INFORMATION_MESSAGE);
            timetable selectedtt = cm.getTimeTableByDay((String) namebox.getSelectedItem());
            jTextArea1.setText(selectedtt.getContent());
        } else {
            JOptionPane.showMessageDialog(this, "There is an error saving your timetable.\nPlease check SQL log for more details", "Error Saving Note", JOptionPane.ERROR_MESSAGE);
        }
        return ok;
    }

    private void exitBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitBtnActionPerformed
// TODO add your handling code here:
        System.exit(0);
}//GEN-LAST:event_exitBtnActionPerformed

    private void nextBTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextBTNActionPerformed
// TODO add your handling code here:
        if (modeFlag == 0) {
            this.nextNote();
        } else if (modeFlag == 1) {
            this.nextDayTimeTable();
        } else {
        }
    }//GEN-LAST:event_nextBTNActionPerformed

    private void backBTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backBTNActionPerformed
// TODO add your handling code here:
        if (modeFlag == 0) {
            this.previousNote();
        } else if (modeFlag == 1) {
            this.previousDayTimeTable();
        } else {
        }
    }//GEN-LAST:event_backBTNActionPerformed

    private void editBTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editBTNActionPerformed
// TODO add your handling code here:
        newBTN.setEnabled(false);
        editBTN.setEnabled(false);
        cancelBTN.setEnabled(true);
        saveBTN.setEnabled(true);
        namebox.setEnabled(false);
        jButton6.setEnabled(false);
        editing = true;
        adding = false;
        setTitle("NoteIt- Editing...");
    }//GEN-LAST:event_editBTNActionPerformed

    private void cancelBTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelBTNActionPerformed
// TODO add your handling code here:
        newBTN.setEnabled(true);
        saveBTN.setEnabled(false);
        cancelBTN.setEnabled(false);
        editBTN.setEnabled(true);
        namebox.setEnabled(true);
        jButton6.setEnabled(true);
        jTextArea1.setText("");
        editing = false;
        adding = false;
        setTitle("NoteIt !");
        if (modeFlag == 0) {
            note selectedNote = cm.gotoSubject((String) namebox.getSelectedItem());
            jTextArea1.setText(selectedNote.getContent());
        } else if (modeFlag == 1) {
            timetable selectedtt = cm.getTimeTableByDay((String) namebox.getSelectedItem());
            jTextArea1.setText(selectedtt.getContent());
        } else {
        }
    }//GEN-LAST:event_cancelBTNActionPerformed

    private void deleteBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteBtnActionPerformed
// TODO add your handling code here:
        String id = namebox.getSelectedItem().toString();
        if (id.equals("")) {
            JOptionPane.showMessageDialog(this, "Enter a valid id for deletion.", "Empty Field", JOptionPane.WARNING_MESSAGE);
            return;
        }
        boolean found = cm.checkId(id);
        if (found == true) {
            boolean ok = cm.deleteNote(id);
            if (ok == true) {
                JOptionPane.showMessageDialog(this, "Note has been successfully deleted.", "Delete Successful", JOptionPane.INFORMATION_MESSAGE);
            // ?
            }
        } else {
            JOptionPane.showMessageDialog(this, "Note id specified does not exist.", "Not not Existing", JOptionPane.INFORMATION_MESSAGE);
        }
}//GEN-LAST:event_deleteBtnActionPerformed

    private void saveBTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveBTNActionPerformed
// TODO add your handling code here:
        if (modeFlag == 0) {
            if (adding == true) {
                this.addNote();
                adding = false;
            }
            if (editing == true) {
                this.editNote();
                editing = false;
            }

        } else if (modeFlag == 1) {
            this.saveTimeTable();
            setTitle("NoteIt !");
        } else {
            setTitle("NoteIt !");
        }
    }//GEN-LAST:event_saveBTNActionPerformed

    private void newBTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newBTNActionPerformed
// TODO add your handling code here:
        jTextArea1.setText("");
        saveBTN.setEnabled(true);
        newBTN.setEnabled(false);
        cancelBTN.setEnabled(true);
        editBTN.setEnabled(false);
        namebox.setEnabled(false);
        jButton6.setEnabled(false);
        //noteidTF.setText(""); ?
        editing = false;
        adding = true;
        setTitle("NoteIt- Adding ...");
    }//GEN-LAST:event_newBTNActionPerformed

    private void clearBTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearBTNActionPerformed
// TODO add your handling code here:
        jTextArea1.setText("");
    }//GEN-LAST:event_clearBTNActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
// TODO add your handling code here:
        if (modeFlag == 0) {
            note selectedNote = cm.gotoSubject((String) namebox.getSelectedItem());
            jTextArea1.setText(selectedNote.getContent());
        } else if (modeFlag == 1) {
            timetable selectedtt = cm.getTimeTableByDay((String) namebox.getSelectedItem());
            jTextArea1.setText(selectedtt.getContent());
        } else {
        }

    }//GEN-LAST:event_jButton6ActionPerformed

private void modeBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_modeBtnActionPerformed
// TODO add your handling code here:
    if (modeFlag == 0) {
        timetableMode();
    } else if (modeFlag == 1) {
        noteMode();
    } else {
    }
}//GEN-LAST:event_modeBtnActionPerformed
    
    public void initTrayIcon(){        
        
        if (SystemTray.isSupported()) {
            
            SystemTray tray = SystemTray.getSystemTray();
            Image image = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/images/NoteIt !-icon1.gif"));
            System.out.println("Image taken: "+image);
            
            ActionListener exitListener = new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    System.exit(0);
                }
            };
            
            ActionListener restoreListener = new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    restore();
                }
            };
            
            PopupMenu popup = new PopupMenu();
            MenuItem exitItem = new MenuItem("Exit NoteIt !");
            MenuItem restoreItem = new MenuItem("Restore NoteIt !");
            exitItem.addActionListener(exitListener);
            restoreItem.addActionListener(restoreListener);
            popup.add(restoreItem);
            popup.add(exitItem);
            trayIcon = new TrayIcon(image, "NoteIt !", popup);            
            ActionListener actionListener = new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    trayIcon.displayMessage("NoteIt !",
                            "Created solely by: Tay Wei Ze Gerald",
                            TrayIcon.MessageType.INFO);
                    restore();                    
                }
            };            
            trayIcon.setImageAutoSize(true);
            trayIcon.addActionListener(actionListener);
           try {
                tray.add(trayIcon);
            } catch (AWTException e) {
                System.err.println("TrayIcon could not be added.");
            }
       }
    }
    
    public void NumberFormatExceptionAlert(){
        //noteidTF.setText(""); ?
        System.out.println("Text Clear");
        JOptionPane.showMessageDialog(this,"Enter a valid id .","Invalid Field",JOptionPane.WARNING_MESSAGE);
        
    }
    
    public String getWeekday(){
        String weekday = null;
        java.util.Calendar jCal = java.util.Calendar.getInstance();
        if(jCal.get(Calendar.DAY_OF_WEEK)==Calendar.MONDAY){
            weekday = "Monday";
        }
        else if(jCal.get(Calendar.DAY_OF_WEEK)==Calendar.TUESDAY){
            weekday = "Tuesday";
        }
        else if(jCal.get(Calendar.DAY_OF_WEEK)==Calendar.WEDNESDAY){
            weekday = "Wednesday";
        }
        else if(jCal.get(Calendar.DAY_OF_WEEK)==Calendar.THURSDAY){
            weekday = "Thursday";
        }
        else if(jCal.get(Calendar.DAY_OF_WEEK)==Calendar.FRIDAY){
            weekday = "Friday";
        }
        else if(jCal.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY){
            weekday = "Saturday";
        }
        else if(jCal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
            weekday = "Sunday";
        }
        else{
            
        }
        return weekday;
    }
    
    public String nextDay(String currentDay){
        if(currentDay.equals("Monday")){
            return "Tuesday";
        }
        else if(currentDay.equals("Tuesday")){
            return "Wednesday";
        }
        else if(currentDay.equals("Wednesday")){
            return "Thursday";
        }
        else if(currentDay.equals("Thursday")){
            return "Friday";
        }
        else if(currentDay.equals("Friday")){
            return "Saturday";
        }
        else if(currentDay.equals("Saturday")){
            return "Sunday";
        }
        else if(currentDay.equals("Sunday")){
            return "Monday";
        }
        else{
            return null;
        }
    }
    
    public String previousDay(String currentDay){
        if(currentDay.equals("Monday")){
            return "Sunday";
        }
        else if(currentDay.equals("Tuesday")){
            return "Monday";
        }
        else if(currentDay.equals("Wednesday")){
            return "Tuesday";
        }
        else if(currentDay.equals("Thursday")){
            return "Wednesday";
        }
        else if(currentDay.equals("Friday")){
            return "Thursday";
        }
        else if(currentDay.equals("Saturday")){
            return "Friday";
        }
        else if(currentDay.equals("Sunday")){
            return "Saturday";
        }
        else{
            return null;
        }
    }
    
    public static MainFrame getFrame(){
        return frame;
    }
    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new MainFrame().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton backBTN;
    private javax.swing.JPanel basePane;
    private javax.swing.JButton cancelBTN;
    private javax.swing.JButton clearBTN;
    private javax.swing.JPanel controlPane;
    private javax.swing.JPanel controlPane2;
    private javax.swing.JPanel controlPane3;
    private javax.swing.JButton deleteBtn;
    private javax.swing.JButton editBTN;
    private javax.swing.JButton exitBtn;
    private javax.swing.JButton jButton6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JToolBar jToolBar3;
    private javax.swing.JToolBar jToolBar4;
    private javax.swing.JButton modeBtn;
    private javax.swing.JComboBox namebox;
    private javax.swing.JButton newBTN;
    private javax.swing.JButton nextBTN;
    private javax.swing.JButton saveBTN;
    // End of variables declaration//GEN-END:variables
    
}
